# -*- coding: UTF-8 -*-
from django.db import models
from django.contrib.auth.models import User
from django import forms
from django.db import models

# Create your models here.
# Opisuje wszystkie możliwe do użycia przełączniki.
# Na podstawie tych wartości generowanych jest widok
# dla użytkownika (true/false - pokaż/ukryj).
class PingPermissionForOption(models.Model):
    # Bind permission to the user
    user = models.ForeignKey(User)
    aOption = models.BooleanField(default=1, verbose_name="-a")
    A_Option = models.BooleanField(default=1, verbose_name="-A")
    bOption = models.BooleanField(default=1, verbose_name="-b")
    B_Option = models.BooleanField(default=1, verbose_name="-B")
    dOption = models.BooleanField(default=1, verbose_name="-d")
    fOption = models.BooleanField(default=1, verbose_name="-f")
    L_Option = models.BooleanField(default=1, verbose_name="-L")
    nOption = models.BooleanField(default=1, verbose_name="-n")
    qOption = models.BooleanField(default=1, verbose_name="-q")
    R_Option = models.BooleanField(default=1, verbose_name="-R")
    rOption = models.BooleanField(default=1, verbose_name="-r")
    UOption = models.BooleanField(default=1, verbose_name="-U")
    vOption = models.BooleanField(default=1, verbose_name="-v")
    V_Option = models.BooleanField(default=1, verbose_name="-V")

# Opisuje wszystkie możliwe do użycia parametry.
# Na podstawie tych wartości generowanych jest widok
# dla użytkownika (true/false - pokaż/ukryj).
class PingPermissionForParameter(models.Model):
    # Bind permission to the user
    user = models.ForeignKey(User)
    cOption = models.BooleanField(default=1, verbose_name="-c count")
    iOption = models.BooleanField(default=1, verbose_name="-i interval")
    lOption = models.BooleanField(default=1, verbose_name="-l preload")
    pOption = models.BooleanField(default=1, verbose_name="-p pattern")
    sOption = models.BooleanField(default=1, verbose_name="-s packetsize")
    tOption = models.BooleanField(default=1, verbose_name="-t ttl")
    I_Option = models.BooleanField(default=1, verbose_name="-I interface")
    MOption = models.BooleanField(default=1, verbose_name="-M hint")
    Q_Option = models.BooleanField(default=1, verbose_name="-Q tos")
    S_Option = models.BooleanField(default=1, verbose_name="-S sndbuf")
    T_Option = models.BooleanField(default=1, verbose_name="-T timestamp option")
    wOption = models.BooleanField(default=1, verbose_name="-w deadline")
    W_Option = models.BooleanField(default=1, verbose_name="-W timeout")

# Opisuje formularz, jaki zostanie wygenerowany dla parametrów polecenia.
# Definiuje walidację danego pola, jego etykietę oraz tekst podpowiedzi.
class PingFormForParameters(forms.Form):
    cOption = forms.IntegerField(
        required = False,
        label = '-c',
        help_text = 'count',
        min_value = 1,)
    iOption = forms.FloatField(
        required = False,
        label = '-i',
        help_text = 'interval')
    lOption = forms.IntegerField(
        required = False,
        label = '-l',
        help_text = 'preload',
        min_value = 1,)
    pOption = forms.CharField(
        max_length=128,
        required = False,
        label = '-p',
        help_text = 'pattern')
    sOption = forms.IntegerField(
        required = False,
        label = '-s',
        help_text = 'packetsize',
        min_value = 1,)
    tOption = forms.IntegerField(
        required = False,
        label = '-t',
        help_text = 'ttl',
        max_value = 255,
        min_value = 1,)
    I_Option = forms.CharField(
        max_length=128,
        required = False,
        label = '-I',
        help_text = 'interface',)
    MOption = forms.CharField(
        max_length=128,
        required = False,
        label = '-M',
        help_text = 'hint',)
    Q_Option = forms.CharField(
        max_length=128,
        required = False,
        label = '-Q',
        help_text = 'tos',)
    S_Option = forms.CharField(
        max_length=128,
        required = False,
        label = '-S',
        help_text = 'sndbuf',)
    T_Option = forms.CharField(
        max_length=128,
        required = False,
        label = '-T',
        help_text = 'timestamp option',)
    wOption = forms.IntegerField(
        required = False,
        label = '-w',
        help_text = 'deadline',
        min_value = 1,)
    W_Option = forms.IntegerField(
        required = False,
        label = '-W',
        help_text = 'timeout',
        min_value = 1,)

# Opisuje formularz, jaki zostanie wygenerowany dla parametrów polecenia.
# Definiuje walidację danego pola, jego etykietę oraz tekst podpowiedzi.
class DestinationForm(forms.Form):
    destination = forms.CharField(
        max_length = 128,
        required = True,
        help_text = 'destination',)

# Opisuje formularz, jaki zostanie wygenerowany dla opcji polecenia.
# Definiuje walidację danego pola, jego etykietę oraz tekst podpowiedzi.
class PingFormForOptions(forms.Form):
    aOption = forms.BooleanField(
        required = False,
        label = '-a',
        help_text = 'Audible ping.')
    A_Option = forms.BooleanField(
        required = False,
        label = '-A',
        help_text = 'Adaptive ping. Interpacket interval adapts to round-trip time, so that effectively not more than one (or more, if preload is set) unanswered probes present in the network. Minimal interval is 200msec for not super-user. On networks with low rtt this mode is essentially equivalent to flood mode.')
    bOption = forms.BooleanField(
        required = False,
        label = '-b',
        help_text = 'Allow pinging a broadcast address.')
    B_Option = forms.BooleanField(
        required = False,
        label = '-B',
        help_text = 'Do not allow ping to change source address of probes. The address is bound to one selected when ping starts.')
    dOption = forms.BooleanField(
        required = False,
        label = '-d',
        help_text = 'Set the SO_DEBUG option on the socket being used. Essentially, this socket option is not used by Linux kernel.')
    fOption = forms.BooleanField(
        required = False,
        label = '-f',
        help_text = 'Flood ping. For every ECHO_REQUEST sent a period ``.'' is printed, while for ever ECHO_REPLY received a backspace is printed. This provides a rapid display of how many packets are being dropped. If interval is not given, it sets interval to zero and outputs packets as fast as they come back or one hundred times per second, whichever is more. Only the super-user may use this option with zero interval.')
    L_Option = forms.BooleanField(
        required = False,
        label = '-L',
        help_text = 'Suppress loopback of multicast packets. This flag only applies if the ping destination is a multicast address.')
    nOption = forms.BooleanField(
        required = False,
        label = '-n',
        help_text = 'Numeric output only. No attempt will be made to lookup symbolic names for host addresses.')
    qOption = forms.BooleanField(
        required = False,
        label = '-q',
        help_text = 'Quiet output. Nothing is displayed except the summary lines at startup time and when finished.')
    R_Option = forms.BooleanField(
        required = False,
        label = '-R',
        help_text = 'Record route. Includes the RECORD_ROUTE option in the ECHO_REQUEST packet and displays the route buffer on returned packets. Note that the IP header is only large enough for nine such routes. Many hosts ignore or discard this option.')
    rOption = forms.BooleanField(
        required = False,
        label = '-r',
        help_text = 'Bypass the normal routing tables and send directly to a host on an attached interface. If the host is not on a directly-attached network, an error is returned. This option can be used to ping a local host through an interface that has no route through it provided the option -I is also used.')
    UOption = forms.BooleanField(
        required = False,
        label = '-U',
        help_text = 'Print full user-to-user latency (the old behaviour). Normally ping prints network round trip time, which can be different f.e. due to DNS failures.')
    vOption = forms.BooleanField(
        required = False,
        label = '-v',
        help_text = 'Verbose output.')
    V_Option = forms.BooleanField(
        required = False,
        label = '-V',
        help_text = 'Show version and exit.')
